<template>
	<view class="u-p-30">
		<view class="u-p-x-20 bg-white rounded-10">
			<order-item-list-good :item="info"></order-item-list-good>
			<view class="u-m-t-20">
				<view class="u-p-10 border rounded-10" style="background-color: #f8f7f7;">
					<u-input v-model="content" type="textarea" />
				</view>
				<text class="flex u-p-y-10">晒图，最多上传5张</text>
				<u-upload :auto-upload="false" ref="uUpload" maxCount="5"></u-upload></view>
			<view class="u-p-y-30">
				<dy-button width="576rpx" size="default" @click="sure">提交</dy-button>
			</view>
		</view>
	</view>
</template>

<script>
	import { OrderCenterApi } from '@/api/serves.js'
	import { mapActions } from 'vuex'
	export default {
		data() {
			return {
				info: {},
				content: '',
			}
		},
		onLoad(options) {
			console.log('options', options);
			this.info = JSON.parse(options.info)
		},
		methods: {
			...mapActions({ upload:'user/upload'}),
			sure() {
				console.log('image list,' , this.$refs.uUpload.lists)
				if(!this.content) return this.$Toast('请输入评价内容')
				let files = this.$refs.uUpload.lists
				this.upload(files).then(res=> {
					console.log(899898, res);
					let params = {
						order_id: this.info.order_id,
						goods_id: this.info.goods_id,
						content: this.content,
						images: ''
					}
					if(res.length>0) {
						params.images = res.length == 1 ? res[0]: res.join(',')
					}
					console.log(params);
					this.apply(params)
				})
			},
			apply(params) {
				this.$ShowLoading()
				OrderCenterApi.comments_add(params).then(res=>{
					console.log('平价' , res)
					this.$HideLoading()
					this.$Toast(res.msg)
					if(res.code==1){
						uni.$emit('orderClick')
						uni.navigateBack()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
